using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Audio;

namespace Services
{
	public enum SoundType
	{ 
		BoardComplete,
		Fumble,
		Pencil,
		TurnPage1,
		TurnPage2
	}

	public class SoundLibrary
	{
		protected Dictionary<SoundType, SoundEffect> audio;
		private Random rnd;
		private ContentManager content;

		public SoundLibrary(ContentManager content)
		{
			this.content = content;
			audio = new Dictionary<SoundType, SoundEffect>();
			rnd = new Random(DateTime.Now.Millisecond);
		}
		
		public void LoadSoundFx()
		{
			audio.Add(SoundType.TurnPage1, content.Load<SoundEffect>("Audio/TurnPage1"));
			audio.Add(SoundType.TurnPage2, content.Load<SoundEffect>("Audio/TurnPage2"));
			audio.Add(SoundType.BoardComplete, content.Load<SoundEffect>("Audio/BoardComplete"));
			audio.Add(SoundType.Fumble, content.Load<SoundEffect>("Audio/Fumble"));
			audio.Add(SoundType.Pencil, content.Load<SoundEffect>("Audio/Pencil"));
		}

		public bool AudioExists(SoundType name)
		{
			return audio.ContainsKey(name);
		}

		public void PlaySound(SoundType name)
		{ 
			audio[name].Play();
		}

		public void TurnPageSound()
		{
			if (rnd.Next(2) == 1) audio[SoundType.TurnPage1].Play();
			else audio[SoundType.TurnPage2].Play();
		}

	}
}
